package http_servlet_response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Creared with IntelliJ IDEA.
 * Description:构造重定向页面
 * User:yxd
 * Date:2022-05-31
 * Time:21:23
 */
@WebServlet("/redirect")
public class RedirectServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        //先设置状态码:
//        resp.setStatus(302);
//        //在通过设置setHeader的方式来构造重定向页面,这里直接跳转到搜狗主页
//        resp.setHeader("Location","https://www.sogou.com");
        resp.sendRedirect("https://www.sogou.com");
    }
}
